// 公司名称验证
export function corpName(value) {
    const reg = /^[\u4e00-\u9fa5\(\)()\da-zA-Z&]{2,50}$/gi;
    return !reg.test(value) ? true : false;
}
//账号姓名验证
export function validateAcount(value) {
    const reg = /^[\u4e00-\u9fa5\(\)()\da-zA-Z&]{2,15}$/gi;
    return !reg.test(value) ? true : false;
}
// 手机号验证
export function validatePhone(value) {
    const reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;

    return !reg.test(value) ? true : false;
}
// 验证码验证
export function validateCode(value) {
    const reg = /^[a-zA-Z0-9]{4}$/;
    return !reg.test(value) ? true : false;
}
// 短信验证
export function validatorNote(value) {
    const reg = /^[a-zA-Z0-9]{6}$/;
    return !reg.test(value) ? true : false;
}
// 密码验证
export function validatorPassword(value) {
    const reg = /^(?![0-9]+$)(?![a-zA-Z]+$)(?!([^(0-9a-zA-Z)]|[\(\)])+$)([^(0-9a-zA-Z)]|[\(\)]|[a-zA-Z]|[0-9]){6,}$/;
    return !reg.test(value) ? true : false;
}
export function validatorUrl(value, type = 1) {
    if (type == 1 ? value.startsWith('http') || value.startsWith('https') : value.startsWith('https')) {
        return false;
    } else {
        return true;
    }
}
// 倒计时
export function countDown(num = 60) {
    // eslint-disable-next-line prefer-const
    let timer;
    num--;
    if (num == 0) {
        clearTimeout(timer);
        num = 60;
    }
    timer = setTimeout(() => countDown(num), 1000);
}
// 活动有效期校验
export function endTimeValidator(rule, value, callback) {
    if (new Date(value[1]).getTime() < new Date().getTime()) {
        callback(new Error('结束时间不能小于当前时间'));
    } else {
        callback();
    }
}

export const validateHttp = (rule, value, callback) => {
    if (value === '') {
        callback(new Error('请输入订阅URL'));
    } else {
        const reg = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
        if (reg.test(value)) {
            callback();
        } else {
            callback(new Error('请输入带有http或https的正确URL'));
        }
    }
};

/**
 * form正则校验
 * @params type
 * creditCode(社会信用代码)
 * code(组织机构代码)
 * business(营业执照15位)
 */
export const getRegExp = type => {
    const formReg = {
        creditCode: /^([0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}|[1-9]\d{14})$/,
        code: /^[0-9A-HJ-NPQRTUWXY]{8}-[0-9A-HJ-NPQRTUWXY]$/,
        business: /^\d{15}$/
    };
    return formReg[type];
};
// 邮箱校验
export function validateEmail(value) {
    const reg =
        /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return reg.test(value);
}

// 身份证校验
export function validateIdCard(value) {
    const reg =
        /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/;
    return reg.test(value);
}
